#include "logger.hpp"

cMessage::cMessage(std::string text)
{
    t = text;
    x = MESSAGE_CREATE_X;
    y = MESSAGE_CREATE_Y;
}

cLogger::cLogger()
{

}

cLogger::~cLogger()
{

}

void cLogger::draw(BITMAP * bufor)
{
    for (int i = 0; i < message.size(); i++)
    {
        textprintf_centre_ex(bufor, font, message[i].x, message[i].y, MESSAGE_COLOR, -1, "%s", message[i].t.c_str());
    }
}

void cLogger::actual()
{
    if (message.size() == 0) return;

    for (int i = 0; i < message.size(); i++)
    {
        if (i == 0 || message[i-1].y - GAP_BETWEEN_MESSAGES > MESSAGE_CREATE_Y)
        {
            message[i].y += MESSAGE_STEP;
            if (message[i].y >= MESSAGE_DELETE) message.erase(message.begin() + i);
        }
    }
}

void cLogger::addMessage(std::string text)
{
    message.push_back(cMessage(text));
}

